package com.jiuzhe.commercial.ui.house;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.bean.CalendarBean;
import com.jiuzhe.commercial.constant.Constants;
import com.jiuzhe.commercial.utils.RxBus;
import com.jiuzhe.commercial.utils.UIUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

/**
 * Created by huanghao on 2018/5/7.
 */

public class ListingActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_into_time)
    TextView tvIntoTime;
    @BindView(R.id.tv_leave_time)
    TextView tvLeaveTime;
    @BindView(R.id.et_listing_price)
    EditText etListingPrice;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.listing_activity);
        setTitle("放盘设定");
        setRringTitle("完成");
        tv_right.setOnClickListener(this);
    }

    @Override
    protected void loadData() {
        List<Long> datesLong = new ArrayList<>();
        List<Date> time = Constants.TIME;
        for (Date date : time) {
            datesLong.add(UIUtils.date2Milliseconds(date));
        }

        long maxDate = Collections.max(datesLong);
        long mixDate = Collections.min(datesLong);

        SimpleDateFormat timeFormat = new SimpleDateFormat("MM月dd日");
        tvIntoTime.setText(UIUtils.milliseconds2String(mixDate,timeFormat));
        tvLeaveTime.setText(UIUtils.milliseconds2String(maxDate,timeFormat));
    }

    @Override
    public void onClick(View v) {
       String etPrice =  etListingPrice.getText().toString().trim();
       String startDate =  tvIntoTime.getText().toString().trim();
       String endDate =  tvLeaveTime.getText().toString().trim();
        CalendarBean  calendarBean = new CalendarBean();
        calendarBean.setStartDate(startDate);
        calendarBean.setEndDate(endDate);
        calendarBean.setPrice(etPrice);

        if (TextUtils.isEmpty(etPrice)){
            UIUtils.showToastSafe("请设定放盘价格");
            return;
        }

        RxBus.getInstance().post(calendarBean);
        finish();
    }
}
